package com.zzptc.easyshop.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

@WebServlet(name = "TestCookieServlet")
public class TestCookieServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //System.out.println("..........");
        String name = request.getParameter("name");
        String pwd = request.getParameter("pwd");
        HttpSession se=request.getSession();
        //创建cookie
        Cookie co = new Cookie("username", name);
        Cookie co1 = new Cookie("password", pwd);

        co.setMaxAge(10 * 24 * 60 * 60);//保存十天
        co1.setMaxAge(10 * 24 * 60 * 60);

        response.addCookie(co);
        response.addCookie(co1);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
